home *** CD-ROM | disk | FTP | other *** search
/ The Original Shareware 1.1 / The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso / 32 / bsl.zip / S1.SL next >
Text File  |  1989-11-15  |  4KB  |  146 lines

  1. /* s1.sl -- test strategy for begin ----------------------------------------*/
  2.  
  3. #include "vocab.h"
  4.  
  5. #define TRUE            1
  6. #define FALSE            0
  7.  
  8. #define TRY_TACTIC_TURNS    6
  9.  
  10.  
  11. declare Enemy;        /* Object we are attacking */
  12. declare Main;           /* Task ID of our main */
  13. declare Me;        /* Our Object */
  14.  
  15. declare Weapons, Helm, Engineering, Threat, Success, Tactic;
  16.  
  17. #include "weapons.sl"
  18. #include "tactic.sl"
  19. #include "engine.sl"
  20. #include "helm.sl"
  21.  
  22.  
  23. /* ThreatTask -- choose who to attack --------------------------------------*/
  24. /*                                                                          */
  25. /* Messages understood by main:                                             */
  26. /*                                                                          */
  27. /*--------------------------------------------------------------------------*/
  28.  
  29. function ThreatTask()
  30. {
  31.   declare Enemy, OldEnemy;
  32.  
  33.   for (;;) {
  34.     Enemy = MaxThreat();
  35.     if (?Enemy) {
  36.       if (!?OldEnemy || Enemy != OldEnemy) {
  37.         OldEnemy = Enemy;
  38.         send( Main, [NEW_ENEMY, Enemy] );
  39.       }
  40.     }
  41.     else
  42.       send(Main, [NO_ENEMY]);
  43.  
  44.     suspend;
  45.   }
  46. }
  47.  
  48.  
  49. /* SuccessTask -- determine success of current tactics ---------------------*/
  50.  
  51. function SuccessTask()
  52. {
  53.   declare MyHits, HisHits;
  54.   declare MyStartHits, HisStartHits;
  55.   declare Message;
  56.   declare Turn;
  57.   declare TryingStrategy;
  58.  
  59.   TryingStrategy = FALSE;
  60.  
  61.   for (;;) {
  62.     if (message()) {
  63.       Message = receive();
  64.       switch (Message[0]) {
  65.         case NEW_TACTIC:
  66.           Turn = 0;
  67.           TryingStrategy = TRUE;
  68.           MyStartHits = TotalHits(Me);
  69.           HisStartHits = TotalHits(Enemy);
  70.           break;
  71.  
  72.         default:
  73.           Say(["(SuccessTask) unknown message starting with ", Message[0]]);
  74.           break;
  75.       }
  76.     }
  77.  
  78.     if (TryingStrategy) {
  79.       MyHits = TotalHits(Me) - MyStartHits;
  80.       HisHits = TotalHits(Enemy) - HisStartHits;
  81.       if (++Turn > TRY_TACTIC_TURNS && MyHits > HisHits) {
  82.         send(Main, [NOT_WORKING]);
  83.         TryingStrategy = FALSE;
  84.       }
  85.     }
  86.  
  87.     suspend;
  88.   }
  89. }
  90.  
  91.  
  92. /* main program -- select enemy and kill him -------------------------------*/
  93. /*                                                                          */
  94. /* Messages understood by main:                                             */
  95. /*                                                                          */
  96. /*  NEW_ENEMY <object>                                                      */
  97. /*  NO_ENEMY                                                                */
  98. /*  TRY_NEW_TACTIC                                                          */
  99. /*                                                                          */
  100. /*--------------------------------------------------------------------------*/
  101.  
  102. function main()
  103. {
  104.   declare Message;
  105.  
  106.   Me          = ThisObject();
  107.   Main        = thistask();
  108.   Weapons     = spawn WeaponsTask();
  109.   Helm        = spawn HelmTask();
  110.   Engineering = spawn EngineeringTask();
  111.   Threat      = spawn ThreatTask();
  112.   Success     = spawn SuccessTask();
  113.   Tactic      = spawn TacticTask();
  114.  
  115.   LoadTorps(350);
  116.   send(Weapons, [OPEN_FIRE]);
  117.  
  118.   for (;;) {
  119.     Message = receive();
  120.  
  121.     switch (Message[0]) {
  122.       case NEW_ENEMY:
  123.         Enemy = Message[1];
  124.         send(Weapons, [TARGET, Enemy]);
  125.         send(Success, [NEW_TACTIC]);
  126.         send(Tactic, [NEW_TACTIC]);
  127.         break;
  128.  
  129.       case NO_ENEMY:
  130.         send(Weapons, [HOLD_FIRE]);
  131.         break;
  132.  
  133.       case NOT_WORKING:
  134.         send(Tactic, [NEW_TACTIC]);
  135.         send(Success, [NEW_TACTIC]);
  136.         break;
  137.  
  138.       default:
  139.         Say(["(main) unknown message starting with ", Message[0]]);
  140.         break;
  141.     }
  142.   }
  143. }
  144.  
  145.  
  146.